//
//  LocalOfPlay.m
//  To Feel
//
//  Created by 孙嘉胤 on 16/7/26.
//  Copyright © 2016年 caoyu. All rights reserved.
//

#import "LocalOfPlay.h"
#import "CYPlayerView.h"
#import "Masonry.h"
@interface LocalOfPlay ()
@end

@implementation LocalOfPlay

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationController.navigationBar.hidden = YES;
    self.tabBarController.tabBar.hidden = YES;
    self.playerView = [[CYPlayerView alloc]init];
    
    [self.view addSubview:self.playerView];
    self.playerView.backgroundColor = [UIColor whiteColor];
    [self.playerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    self.playerView.buttonOfShow.hidden = YES;
    self.playerView.buttonOfDown.hidden = YES;
    [self configCY_PlayerViewWithURL:self.URlOfVideo title:nil];
    
    
    //    //强制横屏
    //    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
    //        SEL selector = NSSelectorFromString(@"setOrientation:");
    //        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
    //        [invocation setSelector:selector];
    //        [invocation setTarget:[UIDevice currentDevice]];
    //        int val = UIInterfaceOrientationLandscapeRight;
    //        [invocation setArgument:&val atIndex:2];
    //        [invocation invoke];
    //    }
    //
}


- (void)configCY_PlayerViewWithURL:(NSURL *)URL
                             title:(NSString *)title{
    
    
    [self.playerView cy_playerViewURl:URL];
//    [self.playerView cy_playerViewLabel:title];
    
//    [self.playerView.cy_mArrOfURL addObject:self.playInfoURLOfNormal];
//    if (self.playInfoURLOfHigh) {
//        [self.playerView.cy_mArrOfURL addObject:self.playInfoURLOfHigh];
//    }else{
//        [self.playerView.cy_mArrOfURL addObject:self.playInfoURLOfNormal];
//    }
    
    
    
    
    [self.playerView.buttonOfReturn addTarget:self action:@selector(handleReturn:) forControlEvents:UIControlEventTouchUpInside];
    //    [self.playerView.buttonOfNext addTarget:self action:@selector(handleNext:) forControlEvents:UIControlEventTouchUpInside];
}



- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.playerView removeFromSuperview];
    self.playerView.player = nil;
    //强制竖屏
    //    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
    //        SEL selector = NSSelectorFromString(@"setOrientation:");
    //        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
    //        [invocation setSelector:selector];
    //        [invocation setTarget:[UIDevice currentDevice]];
    //        int val = UIDeviceOrientationPortrait;
    //        [invocation setArgument:&val atIndex:2];
    //        [invocation invoke];
    //    }
    self.navigationController.navigationBar.hidden = YES;
    self.tabBarController.tabBar.hidden = YES;
    
    
    
}

- (void)handleReturn:(UIButton *)button{
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - present推出页面不让竖屏,锁定横屏
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    
    return UIInterfaceOrientationMaskLandscape;
}
@end
